Skip to content

Preserve Ghostscript diagnostics when stderr is not UTF-8 - #1421

Open
hyperammonemia wants to merge 2 commits into
jsvine:developfrom
hyperammonemia:fix/repair-stderr-decoding
Open

hyperammonemia wants to merge 2 commits into
jsvine:developfrom
hyperammonemia:fix/repair-stderr-decoding

Conversation

@hyperammonemia

Copy link
Copy Markdown

When Ghostscript exits with a nonzero status and writes a non-UTF-8 byte to stderr, _repair raises UnicodeDecodeError while decoding the diagnostic. This hides Ghostscript's readable error message.

Decode stderr with errors="replace" so the existing Exception contains that message, with invalid byte sequences replaced by U+FFFD. Valid UTF-8 remains intact. The tests cover both encodings on failure and confirm that a successful repair still returns its PDF bytes when stderr contains a non-UTF-8 warning.

Related to #1145, which reports a similar UnicodeDecodeError when using repair=True. The PDF from that issue is unavailable, so these tests reproduce the failure path with mocked Ghostscript output; they do not reproduce or resolve the underlying PDF repair failure.

Validation:

  • The non-UTF-8 failure regression fails with the old decoder and passes with the change.
  • Full test suite and source distribution build on Python 3.10 through 3.14, with Ghostscript installed: validation run. The workflow checks out and verifies commit beeecc16240d5855c866a697ab210796ad887080.
  • Black, isort, flake8, and strict mypy pass in the same run.

AI assistance: OpenAI Codex prepared the code, tests, and this description and executed the validation. No human review is claimed.

Decode failed-repair diagnostics with replacement and cover invalid bytes, valid UTF-8, and the successful output path. Prepared with OpenAI Codex assistance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant